#pragma once

#include "FileIOTask.h"
#include "..\Common\Plugin.h"

class CFileReadTask : public CFileIOTask, public std::enable_shared_from_this<CFileReadTask>
{
public:
	CFileReadTask(LPCWSTR lpFileName, IFileReaderPtr pCallback, INT64 nOffset, INT64 nLength);
	~CFileReadTask();

	void Start() override;
	void Cancel() override;

private:
	void DoRead();
	void OnIoCompletion(ULONG nIoResult, ULONG_PTR nBytesRead);
	void DoCallback(BufferPtr pBuffer, INT64 nOffset, size_t nLength);

	std::atomic_bool m_bCanceled;
	std::atomic_uint m_nCacheNum;
	std::wstring     m_strFileName;
	IFileReaderPtr   m_pCallback;
	INT64            m_nStartOffset;
	INT64            m_nRemainingSize;
	INT64            m_nPerReadSize;
	HANDLE           m_hFile;
	PTP_IO           m_pTpIo;
	OVERLAPPED       m_overlapped;
	BufferPtr        m_pBuffer;
};
